   package com.javalong.affairs.module.notifything.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

import com.javalong.affairs.R;
import com.javalong.affairs.base.activity.UIHandlerActivity;
import com.javalong.affairs.base.activity.WebViewActivity;
import com.javalong.affairs.module.notifything.adapter.AuditorStatisticAdapter;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.constant.DataType;
import com.javalong.affairs.base.constant.RequestKey;
import com.javalong.affairs.base.data.AllData;
import com.javalong.affairs.base.listener.BaseResponseListener;
import com.javalong.affairs.base.manager.IntentManager;
import com.javalong.affairs.base.model.Auditor;
import com.javalong.affairs.base.model.MessageStatistic;
import com.javalong.affairs.base.model.User;
import com.javalong.affairs.base.ui.TopTitle;
import com.javalong.affairs.base.utils.HttpUtils;
import com.javalong.affairs.base.utils.TimeUtils;
import com.javalong.affairs.base.utils.UrlUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_msgstatistic)
public class AuditStatisticActivity extends UIHandlerActivity implements
		OnItemClickListener {
	@ViewInject(R.id.tv_time)
	private TextView tv_time;
	@ViewInject(R.id.tv_content)
	private TextView tv_content;
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	@ViewInject(R.id.lv_statistic)
	private ListView lv_statistic;
	@ViewInject(R.id.bt_statistic)
	private Button bt_statistic;
	@ViewInject(R.id.tv_statistic_content)
	private TextView tv_statistic_content;

	private String msgId;
	private String simpleMsgId;
	public AuditorStatisticAdapter adapter;
	private List<Auditor> audioList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		topTitle.setOnLeftDrawableClick(this);
		Bundle bundle = getIntent().getBundleExtra(BundleKey.BUNDLE);
		msgId = bundle.getString(BundleKey.MSGID);
		simpleMsgId = bundle.getString(BundleKey.SIMPLEMSGID);
		String time = bundle.getString(BundleKey.TIME);
		String title = bundle.getString(BundleKey.TITLE);
		tv_content.setText(title);
		tv_time.setText(time);
		audioList = new ArrayList<Auditor>();
		adapter = new AuditorStatisticAdapter(this, audioList);
		lv_statistic.setAdapter(adapter);
		bt_statistic.setOnClickListener(this);
		bt_statistic.setVisibility(View.GONE);
		lv_statistic.setOnItemClickListener(this);
		initData();
		initTopUI(time,title);
	}

	private void initTopUI(String time, String title) {
		// TODO Auto-generated method stub
		tv_time.setText(TimeUtils.getFormatTime2(time));
		tv_content.setText(title);
		
	}

	private void initData() {
		User user = (User) AllData.GetInstance().get(
				R.string.data_user_current_user);
		String url = UrlUtils.getUrl("SendMessage", "outList_auditorList");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(RequestKey.ID, simpleMsgId);
		HttpUtils.post(url, params, new BaseResponseListener(
				DataType.AUDITORLIST) {
			@Override
			public void onSuccess(Object obj) {
				super.onSuccess(obj);
				List<Auditor> temp = (List<Auditor>) obj;
				audioList.addAll(temp);
				adapter.notifyDataSetChanged();
			}
		});
	}

	@Override
	public void refresh() {
		super.refresh();
	}

	private void initTopUI(MessageStatistic mstatistic) {
		tv_time.setText(TimeUtils.getFormatTime2(mstatistic.time));
		tv_content.setText(mstatistic.content);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.bt_statistic:
			Bundle bundle = new Bundle();
			bundle.putString(BundleKey.URL,
					UrlUtils.getUrl("SendMessage", "web_message_allMessage"));
			IntentManager.doActivity2(this, WebViewActivity.class, bundle);
			break;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {

	}

}
